package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person person = new Person("李四", 33);
        System.out.println(person);

        Class cls = Class.forName("reflect.Person");


        Constructor c = cls.getConstructor(String.class, int.class);
        Object obj = c.newInstance("王五", 22);
        System.out.println(obj);

        Constructor c1 = cls.getConstructor(String.class);
        Object obj1 = c1.newInstance("赵六");
        System.out.println(obj1);
    }

}

